<?php

namespace app\payment\model;

use app\user\model\User as UserModel;
use think\Model;

/**
 * 商户信息模型
 */
class MerchantInfo extends Model {

    // 设置当前模型对应的完整数据表名称
    protected $name = 'payment_merchant_info';
    // 自动写入时间戳
    protected $autoWriteTimestamp = true;

    /**
     * 获取所有已经完成的商户号的商户信息和名称，差集
     * @return array
     */
    public static function allMerchant() {
        $Mconfigs = self::column('id');
        $Users = UserModel::column('nickname', 'merchant_id');

        return getOneTwoArray($Mconfigs, $Users);
    }

    /**
     * 获得还未完成的商户信息
     * @return mixed
     */
    public static function getMerchant() {
        $users = UserModel::column('nickname', 'merchant_id');
        // 获取已经设置好的商户号配置
        $all_merchant = self::column('id');
        // 获取所有用户的商户号
        $keys = array_keys($users);
        // 计算数组的差集
        $diff = array_diff($keys, $all_merchant);
        $arr = [];
        foreach ($diff as $value) {
            $arr[$value] = $users[$value];
        }
        return $arr;
    }

}
